package service;

import Dao.GoodsDao;
import model.Category;
import model.Goods;
import model.Page;


import java.sql.SQLException;
import java.util.List;

public class GoodsService {
    private GoodsDao gDao=new GoodsDao();
    public List<Goods> selectGoodsByTypeID(int typeID)
    {
        List<Goods> list=null;
        try {
            list=gDao.selectGoodsByTypeID(typeID);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    public float getPriceById(int id) {
        float price = 0;
        try{
            price=gDao.getPriceById(id);
        }catch(SQLException e){
            e.printStackTrace();
        }
        return price;
    }
    public int getUserIdById(int id){
        int userId=0;
        try{
            userId=gDao.getUserIdById(id);
        }catch (SQLException e){
            e.printStackTrace();
        }
        return userId;
    }
    public List<Goods> GetAllProducts()
    {
        List<Goods> list=null;
        try {
            list=gDao.GetAllProduct();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    public List<Goods> GetProductsByUserId(int userId)
    {
        List<Goods> list=null;
        try {
            list=gDao.GetProductByUserId(userId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    public List<Goods> GetNotRemovedProducts(int userId,boolean is_removed)
    {
        List<Goods> list=null;
        try {
            list=gDao.GetNotRemovedProductByUserId(userId,is_removed);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    public List<Goods> GetIsRemovedProducts(int userId,boolean is_removed)
    {
        List<Goods> list=null;
        try {
            list=gDao.GetIsRemovedProductByUserId(userId,is_removed);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
//
    public Goods getGoodsById(int id) {
        Goods g=null;
        try {
            g = gDao.getGoodsById(id);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return g;
    }
    public void insert(Goods goods) {
        try {
            gDao.insert(goods);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public void update(Goods goods) {
        try {
            gDao.update(goods);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public void delete(int id) {
        try {
            gDao.delete(id);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
